{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-04-18T07:20:59.537649300Z",
     "start_time": "2024-04-18T07:20:57.346343600Z"
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.datasets import fetch_california_housing\n",
    "from sklearn.linear_model import LinearRegression, SGDRegressor, Ridge, LogisticRegression, Lasso\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.metrics import mean_squared_error, classification_report, roc_auc_score\n",
    "import joblib\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "获取特征值\n",
      "(20640, 8)\n",
      "--------------------------------------------------\n",
      "[   8.3252       41.            6.98412698    1.02380952  322.\n",
      "    2.55555556   37.88       -122.23      ]\n",
      "目标值\n",
      "[4.526 3.585 3.521 ... 0.923 0.847 0.894]\n",
      "--------------------------------------------------\n",
      "['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude']\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "线性回归直接预测房子价格\n",
    ":return: None\n",
    "\"\"\"\n",
    "# 获取数据\n",
    "lb = fetch_california_housing(data_home='data')\n",
    "\n",
    "print(\"获取特征值\")\n",
    "print(lb.data.shape)\n",
    "print('-' * 50)\n",
    "print(lb.data[0])\n",
    "print(\"目标值\")\n",
    "print(lb.target)\n",
    "# print(lb.DESCR)\n",
    "print('-' * 50)\n",
    "print(lb.feature_names)\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-18T07:21:26.847427100Z",
     "start_time": "2024-04-18T07:21:26.619549100Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "MedInc - 中位收入（Median Income）\n",
    "HouseAge - 房屋年龄（House Age）\n",
    "AveRooms - 平均房间数（Average Number of Rooms）\n",
    "AveBedrms - 平均卧室数（Average Number of Bedrooms）\n",
    "Population - 人口数量（Population）\n",
    "AveOccup - 平均居住人数（Average Occupancy）\n",
    "Latitude - 纬度（Latitude）\n",
    "Longitude - 经度（Longitude）"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "(20640,)"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lb.target.shape"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-04-18T07:30:49.306409400Z",
     "start_time": "2024-04-18T07:30:49.245430600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(15480, 8)\n"
     ]
    }
   ],
   "source": [
    "# 分割数据集到训练集和测试集\n",
    "x_train, x_test, y_train, y_test = train_test_split(lb.data, lb.target, test_size=0.25, random_state=1)\n",
    "#\n",
    "print(x_train.shape)\n",
    "#\n",
    "# # 进行标准化处理(?) 目标值处理？\n",
    "# # 特征值和目标值是都必须进行标准化处理, 实例化两个标准化API\n",
    "std_x = StandardScaler()\n",
    "#\n",
    "x_train = std_x.fit_transform(x_train)\n",
    "x_test = std_x.transform(x_test)\n",
    "\n",
    "# 目标值进行了标准化\n",
    "std_y = StandardScaler()\n",
    "#\n",
    "# temp = y_train.reshape(-1, 1) #-1代表把剩余的元素都堆到哪一维\n",
    "#\n",
    "# #标签进行标准化\n",
    "# # 目标值是一维的，这里需要传进去2维的\n",
    "# y_train = std_y.fit_transform(y_train.reshape(-1, 1))\n",
    "# print(y_train.shape)\n",
    "# y_test = std_y.transform(y_test.reshape(-1, 1))\n",
    "# print(y_test.shape)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-04-18T08:00:19.108245400Z",
     "start_time": "2024-04-18T08:00:19.046279100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "array([[1],\n       [2],\n       [3]])"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test1=np.array([1,2,3])\n",
    "test1.reshape(-1,1)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "回归系数 [ 0.83167028  0.12159502 -0.26758589  0.30983997 -0.00518054 -0.04040421\n",
      " -0.90736902 -0.88212727]\n",
      "正规方程测试集里面每个房子的预测价格： [2.12391852 0.93825754 2.7088455  1.70873764 2.82954754 3.50376456\n",
      " 3.0147162  1.62781292 1.74317518 2.01897806]\n",
      "正规方程的均方误差： 0.5356532845422556\n"
     ]
    }
   ],
   "source": [
    "# # estimator预测\n",
    "# # # 正规方程求解方式预测结果，正规方程进行线性回归\n",
    "lr = LinearRegression()\n",
    "# fit是耗时的\n",
    "lr.fit(x_train, y_train)\n",
    "#回归系数可以看特征与目标之间的相关性\n",
    "print('回归系数', lr.coef_)\n",
    "#\n",
    "y_predict = lr.predict(x_test)\n",
    "# 预测测试集的房子价格，通过inverse得到真正的房子价格\n",
    "# y_lr_predict = std_y.inverse_transform(y_predict)\n",
    "# 保存训练好的模型，模型中保存的是w的值，也保存了模型结构\n",
    "#保存模型放在fit之后即可\n",
    "joblib.dump(lr, \"./tmp/test.pkl\")\n",
    "print(\"正规方程测试集里面每个房子的预测价格：\", y_predict[0:10])\n",
    "#下面是求测试集的损失\n",
    "print(\"正规方程的均方误差：\", mean_squared_error(y_test, y_predict))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-18T08:00:22.824207400Z",
     "start_time": "2024-04-18T08:00:22.800216100Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 2 加载保存的模型"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "保存的模型预测的结果： [2.12391852 0.93825754 2.7088455  ... 1.24263061 2.73771901 1.75800594]\n",
      "正规方程的均方误差： 0.5356532845422556\n"
     ]
    }
   ],
   "source": [
    "model = joblib.load(\"./tmp/test.pkl\")\n",
    "# # 因为目标值进行了标准化，一定要把预测后的值逆向转换回来\n",
    "y_predict = model.predict(x_test)\n",
    "\n",
    "#\n",
    "print(\"保存的模型预测的结果：\", y_predict)\n",
    "print(\"正规方程的均方误差：\", mean_squared_error(y_test, y_predict))\n",
    "\n",
    "# print(\"正规方程inverse后的均方误差：\", mean_squared_error(std_y.inverse_transform(y_test),\n",
    "#                                                std_y.inverse_transform(y_predict)))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-18T08:02:48.423774300Z",
     "start_time": "2024-04-18T08:02:48.409780900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "data": {
      "text/plain": "0.375"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_true = [3, -0.5, 2, 7]\n",
    "y_pred = [2.5, 0.0, 2, 8]\n",
    "mean_squared_error(y_true, y_pred)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "0.375"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#人工求均方误差\n",
    "(np.square(3 - 2.5) + np.square(0.5) + 1) / 4\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 3 线性回归之梯度下降去进行房价预测"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "梯度下降的回归系数 [ 0.83695692  0.12210043 -0.46563628 -0.00250449 -0.0104465  -0.0445106\n",
      " -0.92420368 -0.88814517]\n",
      "梯度下降的均方误差： 0.7135148922306961\n"
     ]
    }
   ],
   "source": [
    "# 梯度下降去进行房价预测,数据量大要用这个\n",
    "# learning_rate的不同方式，代表学习率变化的算法不一样,比如constant,invscaling,adaptive\n",
    "# 默认可以去调 eta0 = 0.008，会改变learning_rate的初始值\n",
    "# learning_rate='optimal',alpha是正则化力度，但是会影响学习率的值，由alpha来算学习率\n",
    "# penalty代表正则化，分为l1和l2\n",
    "sgd = SGDRegressor(eta0=0.01, penalty='l2',max_iter=1000)\n",
    "# # 训练\n",
    "sgd.fit(x_train, y_train)\n",
    "#\n",
    "print('梯度下降的回归系数', sgd.coef_)\n",
    "#\n",
    "# 预测测试集的房子价格\n",
    "# y_sgd_predict = std_y.inverse_transform(sgd.predict(x_test).reshape(-1, 1))\n",
    "y_predict = sgd.predict(x_test)\n",
    "# print(\"梯度下降测试集里面每个房子的预测价格：\", y_sgd_predict)\n",
    "print(\"梯度下降的均方误差：\", mean_squared_error(y_test, y_predict))\n",
    "# print(\"梯度下降的原始房价量纲均方误差：\", mean_squared_error(std_y.inverse_transform(y_test), y_sgd_predict))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-18T08:24:58.268634200Z",
     "start_time": "2024-04-18T08:24:58.185688600Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 4 岭回归"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.83166963  0.12159681 -0.26758236  0.30983534 -0.00517992 -0.04040432\n",
      " -0.90735215 -0.88211025]\n",
      "(5160,)\n",
      "岭回归的均方误差： 0.5356531179270396\n"
     ]
    }
   ],
   "source": [
    "# # # 岭回归去进行房价预测\n",
    "#岭回归是对线性回归加入L2正则化，L2正则化是对系数的平方和进行惩罚\n",
    "#alpha就是补偿的系数\n",
    "#正规方程求解，加补偿就可以让正规方程可逆\n",
    "rd = Ridge(alpha=0.02)\n",
    "\n",
    "rd.fit(x_train, y_train)\n",
    "\n",
    "print(rd.coef_)\n",
    "#\n",
    "# # 预测测试集的房子价格\n",
    "print(rd.predict(x_test).shape)\n",
    "# y_rd_predict = std_y.inverse_transform(rd.predict(x_test))\n",
    "y_predict = rd.predict(x_test)\n",
    "# print(\"岭回归里面每个房子的预测价格：\", y_rd_predict)\n",
    "\n",
    "print(\"岭回归的均方误差：\", mean_squared_error(y_test, y_predict))\n",
    "# print(\"岭回归的均方误差：\", mean_squared_error(std_y.inverse_transform(y_test), y_rd_predict))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-18T08:40:50.638600600Z",
     "start_time": "2024-04-18T08:40:50.608620600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(15480, 8)\n",
      "(15480,)\n",
      "[ 0.82655827  0.1225482  -0.25369194  0.29596304 -0.00381001 -0.03948424\n",
      " -0.89646842 -0.87060253]\n",
      "(5160,)\n",
      "--------------------------------------------------\n",
      "Lasso回归的均方误差： 0.5356324125105497\n"
     ]
    }
   ],
   "source": [
    "# # # Lasso回归去进行房价预测\n",
    "#alpha就是补偿的系数\n",
    "print(x_train.shape)\n",
    "print(y_train.shape)\n",
    "ls = Lasso(alpha=0.001)\n",
    "\n",
    "ls.fit(x_train, y_train)\n",
    "\n",
    "print(ls.coef_)\n",
    "#\n",
    "# # 预测测试集的房子价格\n",
    "print(ls.predict(x_test).shape)\n",
    "print('-'*50)\n",
    "# y_ls_predict = std_y.inverse_transform(ls.predict(x_test).reshape(-1,1))\n",
    "y_predict = ls.predict(x_test)\n",
    "# print(\"Lasso回归里面每个房子的预测价格：\", y_rd_predict)\n",
    "#\n",
    "print(\"Lasso回归的均方误差：\", mean_squared_error(y_test, y_predict))\n",
    "# print(\"Lasso回归的均方误差：\", mean_squared_error(std_y.inverse_transform(y_test), y_ls_predict))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-18T08:42:07.337297200Z",
     "start_time": "2024-04-18T08:42:07.180391100Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 5 逻辑回归"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_3616\\315209718.py:3: RuntimeWarning: divide by zero encountered in log\n",
      "  plt.plot(x,-np.log(x))  #以e为底部\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAdkklEQVR4nO3deXzV5YHv8c+TneScJCQ5SSBkgRA2g5EdBCsutdS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j428Bj38D/jxP8P7SngYPAJmCS00d0wzTuPwKNwPbA2yqnM4dr7O947VqiYNdHkD9zg3/ZpwrYBdzldOYwjXsG8Ab+HSHbgZuczjwKY14J1AMD+H9Tuh/4HPC5s37WPwj8N9l1qX/HdQq5iIjL6cxEERGXU1GLiLicilpExOVU1CIiLqeiFhFxORW1iIjLqahFRFzuvwDqPgGcthIZqAAAAABJRU5ErkJggg==\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x=np.arange(0,1,0.01)\n",
    "import matplotlib.pyplot as plt\n",
    "plt.plot(x,-np.log(x))  #以e为底部\n",
    "plt.show()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAcVklEQVR4nO3deXSc1Z3m8e/Vvu+lxbJkWbblFbwgGwMJEBOCQwhLJw0kgZANk2SyTk8zk5NeMqRzTmY63ZA+HToh7GmapZMOMSHgAMEBDLax402SLduS5UVLaa/SYq1154+SHMPYVsmuqrdK9XzOqeOS66Xe31VJD9f3ve+9xlqLiIhErjinCxARkXNTUIuIRDgFtYhIhFNQi4hEOAW1iEiESwjFmxYUFNiKiopQvLWIyIy0c+fOTmut60yvhSSoKyoq2LFjRyjeWkRkRjLGHD3baxr6EBGJcApqEZEIp6AWEYlwCmoRkQinoBYRiXAKahGRCKegFhGJcApqEZEgeKXOzU//2BCS91ZQi4gEwcs1bTz5dlNI3ltBLSISBG7vEIVZKSF5bwW1iEgQuL1DFCuoRUQiV5t3i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gficw6WEWwL+4Y+r8f/L6Q1jzEXW2l4niwqxTwGPW2v/yRhzGfALY8wya63P6cIinVM96kA2zD11jDEmAf8/lbrCUl1oBLRJsDHmw8B3gRuttcNhqi2Upmp3JrAM2GyMacI/jrcxyi8oBvJZnwA2WmtHrbVHgIP4gztaBdLmLwLPAVhr3wFS8C9cNJMFZXNwp4I6kA1zNwJ3TTz/JPAHOzE6H6WmbLMxZiXwM/whHe1jlpPO2W5rrcdaW2CtrbDWVuAfm7/RWrvDmXKDIpCf7+fx96YxxhTgHwppDGONwRZIm48B1wAYYxbjD+qOsFYZfhuBz07M/lgLeKy1rdN+Fwevll6PvxfRAHx34u/uw/9LCv4P8T+Bw8B2oNLpK7xhaPOrgBvYPfHY6HTN4Wj3+47dTJTP+gjwszb4h3zqgH3A7U7XHIY2LwG24J8Rshv4iNM1B6HNTwOtwCj+fyV9Efgy8OXTPuefTHxP9p3vz7ZuIRcRiXC6M1FEJMIpqEVEIpyCWkQkwimoRUQinIJaRCTCKahFRCKcglpEJML9P9lJZhElu/llAAAAAElFTkSuQmCC\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x=np.arange(0,1,0.01)\n",
    "import matplotlib.pyplot as plt\n",
    "plt.plot(x,-np.log(1-x))\n",
    "plt.show()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 699 entries, 0 to 698\n",
      "Data columns (total 11 columns):\n",
      " #   Column                       Non-Null Count  Dtype \n",
      "---  ------                       --------------  ----- \n",
      " 0   Sample code number           699 non-null    int64 \n",
      " 1   Clump Thickness              699 non-null    int64 \n",
      " 2   Uniformity of Cell Size      699 non-null    int64 \n",
      " 3   Uniformity of Cell Shape     699 non-null    int64 \n",
      " 4   Marginal Adhesion            699 non-null    int64 \n",
      " 5   Single Epithelial Cell Size  699 non-null    int64 \n",
      " 6   Bare Nuclei                  699 non-null    object\n",
      " 7   Bland Chromatin              699 non-null    int64 \n",
      " 8   Normal Nucleoli              699 non-null    int64 \n",
      " 9   Mitoses                      699 non-null    int64 \n",
      " 10  Class                        699 non-null    int64 \n",
      "dtypes: int64(10), object(1)\n",
      "memory usage: 60.2+ KB\n",
      "None\n",
      "        Sample code number  Clump Thickness  Uniformity of Cell Size  \\\n",
      "count         6.990000e+02       699.000000               699.000000   \n",
      "unique                 NaN              NaN                      NaN   \n",
      "top                    NaN              NaN                      NaN   \n",
      "freq                   NaN              NaN                      NaN   \n",
      "mean          1.071704e+06         4.417740                 3.134478   \n",
      "std           6.170957e+05         2.815741                 3.051459   \n",
      "min           6.163400e+04         1.000000                 1.000000   \n",
      "25%           8.706885e+05         2.000000                 1.000000   \n",
      "50%           1.171710e+06         4.000000                 1.000000   \n",
      "75%           1.238298e+06         6.000000                 5.000000   \n",
      "max           1.345435e+07        10.000000                10.000000   \n",
      "\n",
      "        Uniformity of Cell Shape  Marginal Adhesion  \\\n",
      "count                 699.000000         699.000000   \n",
      "unique                       NaN                NaN   \n",
      "top                          NaN                NaN   \n",
      "freq                         NaN                NaN   \n",
      "mean                    3.207439           2.806867   \n",
      "std                     2.971913           2.855379   \n",
      "min                     1.000000           1.000000   \n",
      "25%                     1.000000           1.000000   \n",
      "50%                     1.000000           1.000000   \n",
      "75%                     5.000000           4.000000   \n",
      "max                    10.000000          10.000000   \n",
      "\n",
      "        Single Epithelial Cell Size Bare Nuclei  Bland Chromatin  \\\n",
      "count                    699.000000         699       699.000000   \n",
      "unique                          NaN          11              NaN   \n",
      "top                             NaN           1              NaN   \n",
      "freq                            NaN         402              NaN   \n",
      "mean                       3.216023         NaN         3.437768   \n",
      "std                        2.214300         NaN         2.438364   \n",
      "min                        1.000000         NaN         1.000000   \n",
      "25%                        2.000000         NaN         2.000000   \n",
      "50%                        2.000000         NaN         3.000000   \n",
      "75%                        4.000000         NaN         5.000000   \n",
      "max                       10.000000         NaN        10.000000   \n",
      "\n",
      "        Normal Nucleoli     Mitoses       Class  \n",
      "count        699.000000  699.000000  699.000000  \n",
      "unique              NaN         NaN         NaN  \n",
      "top                 NaN         NaN         NaN  \n",
      "freq                NaN         NaN         NaN  \n",
      "mean           2.866953    1.589413    2.689557  \n",
      "std            3.053634    1.715078    0.951273  \n",
      "min            1.000000    1.000000    2.000000  \n",
      "25%            1.000000    1.000000    2.000000  \n",
      "50%            1.000000    1.000000    2.000000  \n",
      "75%            4.000000    1.000000    4.000000  \n",
      "max           10.000000   10.000000    4.000000  \n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "逻辑回归做二分类进行癌症预测（根据细胞的属性特征）\n",
    ":return: NOne\n",
    "\"\"\"\n",
    "# 构造列标签名字\n",
    "column = ['Sample code number', 'Clump Thickness', 'Uniformity of Cell Size', 'Uniformity of Cell Shape',\n",
    "          'Marginal Adhesion', 'Single Epithelial Cell Size', 'Bare Nuclei', 'Bland Chromatin', 'Normal Nucleoli',\n",
    "          'Mitoses', 'Class']\n",
    "\n",
    "# 读取数据\n",
    "data = pd.read_csv(\n",
    "    \"https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data\",\n",
    "    names=column)\n",
    "\n",
    "# print(data) #想看可以解除\n",
    "#当你读取数据时，看上去是数值的列，读进来是字符串，说明里边\n",
    "# 存在了非数值情况\n",
    "print(data.info())\n",
    "print(data.describe(include='all'))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "array(['1', '10', '2', '4', '3', '9', '7', '?', '5', '8', '6'],\n      dtype=object)"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Bare Nuclei'].unique()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "(683, 11)\n"
     ]
    }
   ],
   "source": [
    "# 缺失值进行处理\n",
    "data = data.replace(to_replace='?', value=np.nan)\n",
    "#直接删除，哪一行有空值，就删除对应的样本\n",
    "data = data.dropna()\n",
    "print('-' * 50)\n",
    "print(data.shape)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 683 entries, 0 to 698\n",
      "Data columns (total 11 columns):\n",
      " #   Column                       Non-Null Count  Dtype \n",
      "---  ------                       --------------  ----- \n",
      " 0   Sample code number           683 non-null    int64 \n",
      " 1   Clump Thickness              683 non-null    int64 \n",
      " 2   Uniformity of Cell Size      683 non-null    int64 \n",
      " 3   Uniformity of Cell Shape     683 non-null    int64 \n",
      " 4   Marginal Adhesion            683 non-null    int64 \n",
      " 5   Single Epithelial Cell Size  683 non-null    int64 \n",
      " 6   Bare Nuclei                  683 non-null    object\n",
      " 7   Bland Chromatin              683 non-null    int64 \n",
      " 8   Normal Nucleoli              683 non-null    int64 \n",
      " 9   Mitoses                      683 non-null    int64 \n",
      " 10  Class                        683 non-null    int64 \n",
      "dtypes: int64(10), object(1)\n",
      "memory usage: 64.0+ KB\n"
     ]
    }
   ],
   "source": [
    "data.info()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "'Class'"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "column[10]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "data": {
      "text/plain": "array([2, 4], dtype=int64)"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#分类的类别是2和4,对应 \"良性\", \"恶性\"\n",
    "data[column[10]].unique()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "data": {
      "text/plain": "array([-1.21629973, -0.70863282, -0.75174943,  0.04301674, -0.55657068,\n       -0.71054972, -0.99312055, -0.62911518, -0.36280962])"
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 进行数据的分割,第零列是编号\n",
    "x_train, x_test, y_train, y_test = train_test_split(data[column[1:10]], data[column[10]], test_size=0.25,\n",
    "                                                    random_state=1)\n",
    "\n",
    "# 进行标准化处理\n",
    "std = StandardScaler()\n",
    "\n",
    "x_train = std.fit_transform(x_train)\n",
    "x_test = std.transform(x_test)\n",
    "x_train[0]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1.1133701  0.25198952 0.79297925 0.61016803 0.07140358 1.10923362\n",
      "  0.77824325 0.64387342 0.67841755]]\n",
      "[2 2 2 4 2 4 2 2 4 4 2 2 4 2 2 4 2 2 2 2 2 2 2 4 4 2 2 2 4 4 2 2 4 4 2 4 2\n",
      " 2 4 4 4 2 2 4 2 2 2 2 4 2 2 2 4 2 2 2 4 2 2 2 2 4 2 2 2 4 2 4 4 2 2 4 2 2\n",
      " 4 2 2 2 2 2 2 2 4 2 4 4 2 2 2 4 2 2 4 2 2 4 4 2 2 4 2 2 4 4 2 2 2 2 4 2 4\n",
      " 4 2 4 2 4 2 2 2 2 4 2 4 2 2 2 2 2 4 2 2 2 2 2 2 2 4 2 4 4 2 2 4 2 2 2 2 4\n",
      " 2 2 2 2 2 4 2 4 2 4 2 2 4 2 4 2 4 4 2 4 2 2 2]\n",
      "准确率： 0.9824561403508771\n",
      "444    2\n",
      "24     2\n",
      "195    2\n",
      "49     4\n",
      "375    2\n",
      "Name: Class, dtype: int64\n",
      "--------------------------------------------------\n",
      "[[9.49055860e-01 5.09441403e-02]\n",
      " [9.94951356e-01 5.04864403e-03]\n",
      " [9.83692948e-01 1.63070522e-02]\n",
      " [2.69465805e-02 9.73053420e-01]\n",
      " [9.97326877e-01 2.67312287e-03]\n",
      " [7.07379938e-04 9.99292620e-01]\n",
      " [9.91945714e-01 8.05428616e-03]\n",
      " [9.92204547e-01 7.79545284e-03]\n",
      " [7.10879193e-04 9.99289121e-01]\n",
      " [6.55499402e-04 9.99344501e-01]\n",
      " [9.87584036e-01 1.24159640e-02]\n",
      " [9.96201488e-01 3.79851191e-03]\n",
      " [1.32714502e-03 9.98672855e-01]\n",
      " [7.07201257e-01 2.92798743e-01]\n",
      " [9.88095286e-01 1.19047143e-02]\n",
      " [2.61504382e-03 9.97384956e-01]\n",
      " [9.88000738e-01 1.19992620e-02]\n",
      " [9.19674815e-01 8.03251851e-02]\n",
      " [9.89355019e-01 1.06449805e-02]\n",
      " [9.48509379e-01 5.14906206e-02]\n",
      " [9.80482413e-01 1.95175871e-02]\n",
      " [9.97326877e-01 2.67312287e-03]\n",
      " [9.88951335e-01 1.10486654e-02]\n",
      " [4.70715473e-01 5.29284527e-01]\n",
      " [9.70987481e-02 9.02901252e-01]\n",
      " [9.91846436e-01 8.15356378e-03]\n",
      " [9.94133379e-01 5.86662129e-03]\n",
      " [9.95025152e-01 4.97484776e-03]\n",
      " [1.01121007e-02 9.89887899e-01]\n",
      " [3.91921212e-01 6.08078788e-01]\n",
      " [9.64786506e-01 3.52134943e-02]\n",
      " [9.96038692e-01 3.96130797e-03]\n",
      " [2.05163046e-02 9.79483695e-01]\n",
      " [4.26248502e-01 5.73751498e-01]\n",
      " [9.88095286e-01 1.19047143e-02]\n",
      " [3.95210198e-01 6.04789802e-01]\n",
      " [9.91945714e-01 8.05428616e-03]\n",
      " [9.94133379e-01 5.86662129e-03]\n",
      " [3.15429880e-02 9.68457012e-01]\n",
      " [1.96590837e-03 9.98034092e-01]\n",
      " [3.99052058e-03 9.96009479e-01]\n",
      " [9.83804017e-01 1.61959831e-02]\n",
      " [9.34936624e-01 6.50633761e-02]\n",
      " [9.58792316e-04 9.99041208e-01]\n",
      " [9.91031683e-01 8.96831703e-03]\n",
      " [9.97326877e-01 2.67312287e-03]\n",
      " [9.88951335e-01 1.10486654e-02]\n",
      " [9.94133379e-01 5.86662129e-03]\n",
      " [1.88574807e-04 9.99811425e-01]\n",
      " [9.87712861e-01 1.22871392e-02]\n",
      " [9.93924099e-01 6.07590121e-03]\n",
      " [9.82436716e-01 1.75632844e-02]\n",
      " [2.49091860e-02 9.75090814e-01]\n",
      " [9.79659588e-01 2.03404122e-02]\n",
      " [9.72939203e-01 2.70607969e-02]\n",
      " [9.87173771e-01 1.28262295e-02]\n",
      " [1.71580118e-03 9.98284199e-01]\n",
      " [9.96325667e-01 3.67433263e-03]\n",
      " [9.92526979e-01 7.47302135e-03]\n",
      " [9.83692948e-01 1.63070522e-02]\n",
      " [5.17324857e-01 4.82675143e-01]\n",
      " [4.91253829e-06 9.99995087e-01]\n",
      " [9.36105826e-01 6.38941744e-02]\n",
      " [9.92526979e-01 7.47302135e-03]\n",
      " [9.82436716e-01 1.75632844e-02]\n",
      " [4.72921053e-02 9.52707895e-01]\n",
      " [9.94133379e-01 5.86662129e-03]\n",
      " [2.10386535e-03 9.97896135e-01]\n",
      " [1.81840593e-06 9.99998182e-01]\n",
      " [9.83149049e-01 1.68509512e-02]\n",
      " [9.90759862e-01 9.24013842e-03]\n",
      " [2.49317957e-03 9.97506820e-01]\n",
      " [9.75992692e-01 2.40073082e-02]\n",
      " [9.87173771e-01 1.28262295e-02]\n",
      " [1.25263641e-01 8.74736359e-01]\n",
      " [9.82436716e-01 1.75632844e-02]\n",
      " [9.87173771e-01 1.28262295e-02]\n",
      " [9.85306277e-01 1.46937234e-02]\n",
      " [9.94951356e-01 5.04864403e-03]\n",
      " [9.85192166e-01 1.48078343e-02]\n",
      " [9.94557630e-01 5.44237050e-03]\n",
      " [9.94951356e-01 5.04864403e-03]\n",
      " [6.56576240e-03 9.93434238e-01]\n",
      " [9.95114075e-01 4.88592456e-03]\n",
      " [1.18078042e-02 9.88192196e-01]\n",
      " [2.95334457e-04 9.99704666e-01]\n",
      " [9.76154937e-01 2.38450632e-02]\n",
      " [9.76232478e-01 2.37675224e-02]\n",
      " [9.40131964e-01 5.98680361e-02]\n",
      " [2.85338941e-03 9.97146611e-01]\n",
      " [9.97326877e-01 2.67312287e-03]\n",
      " [9.93576820e-01 6.42317967e-03]\n",
      " [3.65932266e-03 9.96340677e-01]\n",
      " [9.96043588e-01 3.95641198e-03]\n",
      " [9.96201488e-01 3.79851191e-03]\n",
      " [5.96851439e-02 9.40314856e-01]\n",
      " [4.28274595e-02 9.57172540e-01]\n",
      " [9.70284729e-01 2.97152709e-02]\n",
      " [9.94557630e-01 5.44237050e-03]\n",
      " [3.59608565e-02 9.64039143e-01]\n",
      " [9.94557630e-01 5.44237050e-03]\n",
      " [9.65083100e-01 3.49168999e-02]\n",
      " [1.98042371e-02 9.80195763e-01]\n",
      " [1.08401289e-03 9.98915987e-01]\n",
      " [9.69933619e-01 3.00663808e-02]\n",
      " [9.91945714e-01 8.05428616e-03]\n",
      " [9.81537291e-01 1.84627094e-02]\n",
      " [9.84824314e-01 1.51756855e-02]\n",
      " [5.35673209e-04 9.99464327e-01]\n",
      " [9.95196303e-01 4.80369670e-03]\n",
      " [1.46284996e-03 9.98537150e-01]\n",
      " [1.26375773e-01 8.73624227e-01]\n",
      " [9.75992692e-01 2.40073082e-02]\n",
      " [2.53916000e-03 9.97460840e-01]\n",
      " [9.91678359e-01 8.32164147e-03]\n",
      " [1.08609653e-02 9.89139035e-01]\n",
      " [9.83692948e-01 1.63070522e-02]\n",
      " [9.88095286e-01 1.19047143e-02]\n",
      " [9.11223933e-01 8.87760670e-02]\n",
      " [9.94133379e-01 5.86662129e-03]\n",
      " [7.53576778e-04 9.99246423e-01]\n",
      " [9.26858175e-01 7.31418247e-02]\n",
      " [1.15113461e-03 9.98848865e-01]\n",
      " [9.76337017e-01 2.36629830e-02]\n",
      " [9.94322311e-01 5.67768858e-03]\n",
      " [9.97413232e-01 2.58676817e-03]\n",
      " [9.92526979e-01 7.47302135e-03]\n",
      " [9.96325667e-01 3.67433263e-03]\n",
      " [1.81532771e-05 9.99981847e-01]\n",
      " [9.70440544e-01 2.95594559e-02]\n",
      " [9.97326877e-01 2.67312287e-03]\n",
      " [9.94557630e-01 5.44237050e-03]\n",
      " [9.94951356e-01 5.04864403e-03]\n",
      " [9.96444251e-01 3.55574937e-03]\n",
      " [9.89484311e-01 1.05156891e-02]\n",
      " [9.80838020e-01 1.91619800e-02]\n",
      " [1.44372052e-02 9.85562795e-01]\n",
      " [9.68809317e-01 3.11906829e-02]\n",
      " [2.43626205e-03 9.97563738e-01]\n",
      " [1.76643683e-01 8.23356317e-01]\n",
      " [6.91626697e-01 3.08373303e-01]\n",
      " [9.94430141e-01 5.56985931e-03]\n",
      " [1.32311461e-01 8.67688539e-01]\n",
      " [9.96038692e-01 3.96130797e-03]\n",
      " [9.91319633e-01 8.68036737e-03]\n",
      " [9.94951356e-01 5.04864403e-03]\n",
      " [9.96325667e-01 3.67433263e-03]\n",
      " [5.94239402e-05 9.99940576e-01]\n",
      " [9.97326877e-01 2.67312287e-03]\n",
      " [9.94765954e-01 5.23404572e-03]\n",
      " [9.88095286e-01 1.19047143e-02]\n",
      " [9.81686962e-01 1.83130384e-02]\n",
      " [9.54084966e-01 4.59150336e-02]\n",
      " [9.24001291e-02 9.07599871e-01]\n",
      " [9.94951356e-01 5.04864403e-03]\n",
      " [2.33107609e-05 9.99976689e-01]\n",
      " [9.82452565e-01 1.75474351e-02]\n",
      " [1.42241722e-02 9.85775828e-01]\n",
      " [9.96325667e-01 3.67433263e-03]\n",
      " [9.91319633e-01 8.68036737e-03]\n",
      " [1.66135879e-04 9.99833864e-01]\n",
      " [9.94133379e-01 5.86662129e-03]\n",
      " [2.73670446e-03 9.97263296e-01]\n",
      " [9.78354492e-01 2.16455081e-02]\n",
      " [6.36845025e-03 9.93631550e-01]\n",
      " [1.05152559e-01 8.94847441e-01]\n",
      " [9.93721999e-01 6.27800131e-03]\n",
      " [2.66850817e-01 7.33149183e-01]\n",
      " [9.83692948e-01 1.63070522e-02]\n",
      " [9.78335673e-01 2.16643274e-02]\n",
      " [9.92204547e-01 7.79545284e-03]]\n",
      "召回率：               precision    recall  f1-score   support\n",
      "\n",
      "          良性       0.97      1.00      0.99       111\n",
      "          恶性       1.00      0.95      0.97        60\n",
      "\n",
      "    accuracy                           0.98       171\n",
      "   macro avg       0.99      0.97      0.98       171\n",
      "weighted avg       0.98      0.98      0.98       171\n",
      "\n",
      "AUC指标： 0.975\n"
     ]
    }
   ],
   "source": [
    "#\n",
    "# # 逻辑回归预测\n",
    "# C正则化力度\n",
    "# solver = 'liblinear'  solver是学习率优化算法，就是学习率会随着epoch的变化而变化\n",
    "#epoch就代表第几次迭代\n",
    "#max_iter 最大迭代次数\n",
    "lg = LogisticRegression(C=0.5, solver='lbfgs')\n",
    "#\n",
    "lg.fit(x_train, y_train)\n",
    "# 逻辑回归的权重参数，了解，没那么重要\n",
    "print(lg.coef_)\n",
    "\n",
    "y_predict = lg.predict(x_test)\n",
    "print(y_predict)\n",
    "print(\"准确率：\", lg.score(x_test, y_test))\n",
    "print(y_test[0:5])\n",
    "print('-'*50)\n",
    "print(lg.predict_proba(x_test))  #得出对应分类的概率\n",
    "# 为什么还要看下召回率，labels和target_names对应\n",
    "# macro avg 平均值  weighted avg 加权平均值\n",
    "print(\"召回率：\", classification_report(y_test, y_predict, labels=[2, 4], target_names=[\"良性\", \"恶性\"]))\n",
    "#AUC计算要求是二分类，不需要是0和1\n",
    "print(\"AUC指标：\", roc_auc_score(y_test, y_predict))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(512, 9)\n",
      "(171, 9)\n"
     ]
    }
   ],
   "source": [
    "print(x_train.shape)\n",
    "print(x_test.shape)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.3025850929940455\n"
     ]
    }
   ],
   "source": [
    "print(-np.log(0.1))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "outputs": [
    {
     "data": {
      "text/plain": "0.10536051565782628"
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-np.log(0.9)\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "data": {
      "text/plain": "3.55"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x=-3/10\n",
    "y=5*x**2+3*x+4\n",
    "y"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
